<template>
  <div id="app">
    <returntop></returntop>

    <div class="rettop"></div>

    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in goodslist.gallery" :key="item.id">
        <img :src="item.img_url" alt="" />
      </van-swipe-item>
    </van-swipe>

    <service></service>

    <div class="goodstitle">
      <p>{{ goodsinfo.name }}</p>
      <p>{{ goodsinfo.goods_brief }}</p>
      <p>￥{{ goodsinfo.retail_price }}</p>
    </div>

    <van-cell is-link @click="showPopup">请选择规格和数量</van-cell>
    <van-popup v-model="show" position="bottom">
      <div class="popup-num">
        <img :src="goodsinfo.primary_pic_url" alt="" class="popup-img" />
        <div class="popup-p">
          <p>价格￥{{ goodsinfo.retail_price }}</p>
          <p>请选择数量</p>
        </div>
      </div>
      <div class="popup-bottom">
        <p>数量</p>
        <van-stepper v-model="value" />
      </div>
    </van-popup>

    <ul class="gooodsspecs">
      <li>商品参数</li>
      <li
        v-for="item in goodslist.attribute"
        :key="item.id"
        class="gooodsspecs-p"
      >
        <p>{{ item.name }}</p>
        <p>{{ item.value }}</p>
      </li>
    </ul>

    <div v-html="goodsinfo.goods_desc" class="goodsdetails"></div>

    <ul class="goodsanswer">
      <li>
        <div class="goodsanswer-top">
          <span></span>
          <p>常见问题</p>
          <span></span>
        </div>
      </li>
      <li
        v-for="item in goodslist.issue"
        :key="item.id"
        class="goodsanswer-bot"
      >
        <div><span></span>{{ item.question }}</div>
        <div>{{ item.answer }}</div>
      </li>
    </ul>

    <ul class="goodslook">
      <div class="goodslook-top">
        <div class="goodsanswer-top">
          <span></span>
          <p>大家都在看</p>
          <span></span>
        </div>
      </div>

      <div class="goodslook-list">
        <li v-for="item in goodslist.productList" :key="item.id">
          <img :src="item.list_pic_url" alt="" />
          <p>{{ item.name }}</p>
          <p>{{ item.retail_price }}</p>
        </li>
        <div class="goodslook-list-bot"></div>
      </div>
    </ul>

    <div class="joincar">
      <div></div>
      <div></div>
      <div @click="showPopup">
        立即购买
        <van-popup v-model="show" position="bottom">
          <div class="popup-num">
            <img :src="goodsinfo.primary_pic_url" alt="" class="popup-img" />
            <div class="popup-p">
              <p>价格￥{{ goodsinfo.retail_price }}</p>
              <p>请选择数量</p>
            </div>
          </div>
          <div class="popup-bottom">
            <p>数量</p>
            <van-stepper v-model="value" />
          </div>
        </van-popup>
      </div>
      <div @click="showPopup">
        加入购物车
        <van-popup v-model="show" position="bottom">
          <div class="popup-num">
            <img :src="goodsinfo.primary_pic_url" alt="" class="popup-img" />
            <div class="popup-p">
              <p>价格￥{{ goodsinfo.retail_price }}</p>
              <p>请选择数量</p>
            </div>
          </div>
          <div class="popup-bottom">
            <p>数量</p>
            <van-stepper v-model="value" />
          </div>
        </van-popup>
      </div>
    </div>
  </div>
</template>

<script type="text/javascript">
import returntop from "../../../components/homecomp/returntop";
import service from "../../../components/homecomp/service";
import { homelist } from "@/api/home/homelist/index";

import { addCart } from "@/api/cart/addCart/index";

export default {
  data() {
    return {
      show: false,
      value: 1,
      openId: localStorage.getItem("openId"),
      goodslist: [],
      goodsinfo: "",
      goodsID: "",
      num:'1'
    };
  },
  methods: {
    showPopup() {
      if(this.show == false){
        this.show = true;
      }else{
        addCart({
          goodsId: this.goodsID.toString(),
          openId: this.openId,
          number: this.num,
        }).then((res)=>{
          console.log(res);
        })
      }
    },
  },
  computed: {},
  components: {
    returntop,
    service,
  },
  async created() {
    var res = await homelist({
      id: this.$route.params.idb,
      openId: this.openId,
    });
    // console.log(res);
    this.goodslist = res;
    this.goodsinfo = res.info;
    // console.log(this.goodsinfo);
    this.goodsID = res.info.id;

    // var result = await addCart({
    //   goodsId: '1015007',
    //   openId: "oQmbb4sNZdxaUQZ0sfYgvtOP2S7c",
    //   number: "1",
    // });
    // console.log(result);

  },
  mounted() {},
};
</script>

<style scoped lang="scss">
#app {
  background-color: #f4f4f4;
}
.rettop {
  height: 46px;
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  // line-height: 150px;
  width: 100%;
  height: 375px;
  text-align: center;
  background-color: #39a9ed;
  img {
    width: 100%;
  }
}
.goodstitle {
  background-color: #fff;
  & :first-child {
    font-size: 18px;
  }
  & :nth-child(2) {
    color: #999;
  }
  & :last-child {
    font-size: 18px;
    color: #b4282d;
  }
}

.van-popup {
  padding: 15px;
  position: fixed;
  bottom: 52px;
}
// vue样式穿透
::v-deep .van-overlay {
  height: 90%;
  position: fixed;
  top: 0;
}
// .mask{
//   z-index: 8;
//   height: 50%;
// }

.popup-num {
  display: flex;
  justify-content: space-between;
  .popup-p {
    width: 241.5px;
    height: 88.5px;
    text-align: left;
    & :first-child {
      color: #b4282d;
    }
  }
  .popup-img {
    width: 88.5px;
    height: 88.5px;
  }
}
.popup-bottom {
  text-align: left;
}

.gooodsspecs {
  text-align: left;
  width: 345px;
  padding: 10px 15px;
  background-color: #fff;
  & li:first-child {
    font-size: 18px;
    padding: 10px 0;
  }
  .gooodsspecs-p {
    display: flex;
    background-color: #f4f4f4;
    font-size: 12px;
    padding: 10px 0;
    margin: 10px;
    color: #000;

    p {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      height: 16px;
      margin: 0;
    }
    & :first-child {
      color: #666;
      width: 67px;
    }
  }
}

.goodsanswer {
  margin-top: 14px;
  background-color: #fff;
}
.goodsanswer-top {
  display: flex;
  justify-content: center;
  padding: 15px 0;
  p {
    margin: 0 8px;
    color: #000;
  }
  span {
    display: inline-block;
    width: 50px;
    height: 1px;
    background-color: #ccc;
    margin-top: 8px;
  }
}

.goodsanswer-bot {
  text-align: left;
  padding: 0 15px;
  & :first-child {
    font-size: 14px;
    color: #000;
    margin: 7.5px 0;
    span {
      display: inline-block;
      width: 4px;
      height: 4px;
      background: #b4282d;
      border-radius: 50%;
      margin: 0 3px 3px 0;
    }
  }
  & :last-child {
    font-size: 14px;
    color: #787878;
    margin-left: 8px;
  }
}

.goodslook {
  margin-top: 30px;
  padding-bottom: 50px;
  .goodslook-top {
    height: 60px;
    background-color: #fff;
  }
  .goodslook-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    li {
      width: 182px;
      background-color: #fff;
      margin-bottom: 6px;
    }
    img {
      width: 151px;
      height: 151px;
    }
    .goodslook-list-bot {
      width: 182px;
      height: 0.1px;
    }
  }
}

.joincar {
  display: flex;
  width: 100%;
  height: 52px;
  background-color: #fff;
  border-top: 1px solid #f4f4f4;
  position: fixed;
  bottom: 0;

  // z-index: 9999;
  & :first-child {
    width: 83px;
    height: 52px;
    background: url(../../../assets/img/images/icon_collect.png) no-repeat;
    background-size: 24px;
    background-position: 30px 15px;
    border-right: 1px solid #f4f4f4;
  }
  & :nth-child(2) {
    width: 83px;
    height: 52px;
    background: url(../../../assets/img/images/ic_menu_shoping_nor.png)
      no-repeat;
    background-size: 24px;
    background-position: 30px 15px;
    border-right: 1px solid #f4f4f4;
  }
  & :nth-child(3) {
    width: 103.5px;
    height: 52px;
    text-align: center;
    line-height: 52px;
  }
  & :nth-child(4) {
    width: 105.5px;
    height: 52px;
    text-align: center;
    line-height: 52px;
    background-color: #b4282d;
    color: #fff;
  }
}
</style>
